<?php
namespace app\common\model;
use app\common\traits\Models;
use think\Model;
use think\facade\{
    App,Request,Config
};
class UserBank extends Model
{
    use Models;
    protected $readonly = [];
    protected $auto     = [];
    protected $insert   = [];
    protected $update   = [];


    //获取器====================================================================================//
    public function getCreateTimeAttr($value)
    {
        return com_time_format($value);
    }
    public function getUpdateTimeAttr($value)
    {
        return com_time_format($value);
    }

    public function getIsDefaultAttr($value)
    {
        return c("type.is_default",$value);
    }
    public function getStatusAttr($value)
    {
        return c("type.bank_status",$value);
    }

  	//关联用户
  	public function user()
    {
        return $this->belongsTo('user','user_id','id');
    }
    //设为默认
 	public function default($user_id,$id)
    {
        model('userBank')::where('user_id' , $user_id)->update(['is_default' => 0]);
    	model('userBank')::where([ ['user_id','=',$user_id] , ['id','=',$id] ])->update(['is_default' => 1]);
    	return true;
    }

    /**
     * 删除
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function del($id){
        if(!is_array($id)) $id = [$id];
        $id = implode(",",$id);
        $this::destroy($id,true);
        return true;
    }
}
